package servlet;

import service.IRainQualityService;
import service.impl.RainQualityServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteRainQuality")
public class DeleteRainQualityServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private IRainQualityService rainQualityService = new RainQualityServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int id = Integer.parseInt(request.getParameter("id"));
        try {
            boolean result = rainQualityService.deleteById(id);
            if (result) {
                response.sendRedirect("RainQualityListServlet");
            } else {
                response.sendRedirect("error.jsp");
            }
        } catch (Exception e) {
            e.printStackTrace();
            response.sendRedirect("error.jsp");
        }
    }
}
